﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Drawing;
using DataAccess;
public partial class ExpertManager_ViewOffUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BtnSEr_Click(object sender, EventArgs e)
    {
        IDataReader datar = null;
        Session["name"] = Tser.Text;
        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("UserName");
        dt.Columns.Add("Family");
        dt.Columns.Add("Address");
        dt.Columns.Add("Telephone");
        dt.Columns.Add("ProvinceName");
        dt.Columns.Add("EmailAddress");
        dt.Columns.Add("Mobile");
        if (RadioButtonList1.SelectedValue == "")
        {

            LBLStatus.Text = "لطفا روش جستجو را انتخاب کنید";
        }

        else if (RadioButtonList1.SelectedItem.Value != "")
        {

            LBLStatus.Visible = false;
            Tser.Enabled = true;

            if (RadioButtonList1.SelectedItem.Value == "Name")
                datar = ExpProvince.FetchByParameter(ExpProvince.Columns.Name, SubSonic.Comparison.Like, "%" + Tser.Text + "%");
            else if (RadioButtonList1.SelectedItem.Value == "LastName")
                datar = ExpProvince.FetchByParameter(ExpProvince.Columns.Family, SubSonic.Comparison.Like,"%"+ Tser.Text+"%");
            else if (RadioButtonList1.SelectedItem.Value == "Mobile")
                datar = ExpProvince.FetchByParameter(ExpProvince.Columns.Mobile, SubSonic.Comparison.Like, "%" + Tser.Text + "%");
            else if (RadioButtonList1.SelectedItem.Value == "NatioCode")
                datar = ExpProvince.FetchByParameter(ExpProvince.Columns.NationalCode, SubSonic.Comparison.Like, "%" + Tser.Text + "%");
            while (datar.Read())
            {
                ProfileCommon p = Profile.GetProfile(datar["UserName"].ToString());
                if (p.Common.Status == "Off")
                {
                    DataRow dr;
                    dr = dt.NewRow();
                    dr["Name"] = datar["Name"].ToString();
                    dr["UserName"] = datar["UserName"].ToString();
                    dr["Family"] = datar["Family"].ToString();
                    dr["Address"] = datar["Address"].ToString();
                    dr["Telephone"] = datar["Telephone"].ToString();
                    dr["ProvinceName"] = datar["ProvinceName"].ToString();
                    dr["EmailAddress"] = datar["EmailAddress"].ToString();
                    dr["Mobile"] = datar["Mobile"].ToString();
                    dt.Rows.Add(dr);
                }
            }
            datar.Close();
            GrdExpert.DataSource = dt;
            GrdExpert.DataBind();
            pnlShowdata.Visible = true;

        }
    }

    protected void GrdExpert_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int Roid = Convert.ToInt32(e.CommandArgument);
        string username = GrdExpert.Rows[Roid].Cells[6].Text;
        MembershipUser user = Membership.GetUser(username);
        Session["UserName"] = user.ToString();
        ProfileCommon p = Profile.GetProfile(Session["UserName"].ToString());
        switch (e.CommandName) { 
            case "Del":
                p.Common.Status = "On";
                p.Save();
                user.IsApproved = true;
                Membership.UpdateUser(user);
                GrdExpert.Rows[Roid].BackColor = Color.White;
                Lblsta1.Text = "کاربر فعال گردید";
        break;
        
        
        }
        
        
    }
}